package com.xyh.system.service.impl;

import com.xyh.system.mapper.DeptMapper;
import com.xyh.system.model.Dept;
import com.xyh.system.service.IDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author kyle
 * @since 2021-01-05
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService {
    @Autowired
    private DeptMapper deptMapper;

    /**
     * 获取所有部门，创建树
     *
     * @return
     */
    @Override
    public List<Dept> selectAllDeptTree() {
        return deptMapper.selectAllDeptTree();
    }

    @Override
    public List<Dept> selectChildDeptByParentId(Integer parentId) {
        return deptMapper.selectChildDeptByParentId(parentId);
    }

    @Override
    public boolean insert(Dept dept) {
        Integer maxOrderNum = baseMapper.selectMaxOrderNum();
        dept.setOrderNum(maxOrderNum + 1);
        return this.save(dept);
    }

}
